<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <h3>账号：abo；密码：123</h3>
    <form action="/login2" method="POST" id="form1">
        <p>
            <input type="text" name="username" id="username">
        </p>
        <p>
            <input type="text" name="pwd" id="pwd">
        </p>
        <p>
            <button>登录</button>
        </p>
    </form>
    <script src="./jquery.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.form/4.3.0/jquery.form.min.js" integrity="sha384-qlmct0AOBiA2VPZkMY3+2WqkHtIQ9lSdAsAn5RUJD/3vA5MKDgSGcdmIv4ycVxyn" crossorigin="anonymous"></script>
    <script>
        // $(function ())是入口函数
        $(function () {
            /*
             获取form元素，调用其ajaxForm(...)方法
             内部的function(data)的data就是后台返回的数据
            */
            $("#form1").ajaxForm(function (data) {
                var data =JSON.parse(data)
                if(data.code==1){
                    alert(data.msg+'登陆次数:'+data.num)
                }
                else if(data.code==0){
                    alert(data.msg)
                    location.href='./file.html'
                }
                else{
                    alert(data.msg)
                }
               
            }
            );
        });
    </script>
</body>

</html>